'''
Created on Sep 11, 2012

@author: Gangli
'''

import time;

UICC_PPS = "/pps/services/cellular/uicc/card0/status_private"
#UICC_PPS = "e:/uicc.txt"

def fib(n):
    if n == 0:
        return 0;
    elif n == 1:
        return 1;
    else:
        return fib(n-1) + fib(n-2);

def uicc_status(status):
    uicc_status_str = 'uicc_state:json:{{"state":"{0}","add_info":0}}\n'.format(status);
    fout = open(UICC_PPS, "a+");   
    fout.write(uicc_status_str);
    fout.flush();
    fout.close();
    print "{0} written to UICC PPS".format(status);

def uicc_stress_test():
    intervals = [];
    for idx in range(8):
        intervals.append(fib(idx % 3));
    print "intervals for test: {0}".format(intervals);
    
    for interval in intervals:
        if interval == 0:
            continue;
        uicc_status("NOT_READY");
        time.sleep(interval);
        uicc_status("READY");
        time.sleep(interval);
    
    print "stress test is done";

if __name__ == '__main__':
    uicc_stress_test();